/******************************************************************************************
 Replication do-file
 Paper: "Attitudes toward education spending when facing a fiscal trade-off: An analysis of stakeholders"
 Journal: European Sociological Review
 Authors: Özel, Parrado, Yıldırım
*******************************************************************************************/

*******************************************************************************************/

/*** Session setup ***/
version 17.0
capture log close
log using "replication.log", text replace
clear all
set more off
set rmsg on
set linesize 255
set seed 26092025



/*** Dependencies ***/
/* estout (eststo/esttab), g538schemes (plotplainblind), ietoolkit (iebaltab), grc1leg (graph combine with shared legend) */
cap which eststo
if _rc ssc install estout
cap which iebaltab
if _rc ssc install ietoolkit
cap which grc1leg
if _rc ssc install grc1leg
cap which scheme-plotplainblind.scheme
if _rc ssc install blindschemes


/* Set scheme with safe fallback */
capture graph set scheme plotplainblind
if _rc {
    di as txt "blindschemes not found; using s2color scheme."
}

*Change working dirrectory to the folder where data file is, then:
/*** Data ***/
* Ensure dataset is present in the working directory
capture confirm file "data.dta"
if _rc {
    di as error "data.dta not found in current directory. Place data.dta next to this do-file."
    exit 601
}

use "data.dta", clear
compress

*Set Graph scheme to 538bw:
set scheme plotplain, permanently

/* Label key variables */
* Outcome labels (only assign if not already labeled)
capture label define outcome_lbl 1 "Much less than now" 2 "Less than now" 3 "More than now" 4 "Much more than now"
capture label values outcome outcome_lbl

* Harmonize factor variable bases for reproducibility.
* Adjust bases if your coding differs.
fvset base 0 parents_students
fvset base 0 SchoolType
fvset base 1 Sex
fvset base 1 Community
fvset base 0 exp

* Safety: some code refers to SchoolType2; create it if absent.
capture confirm variable SchoolType2
if _rc {
    gen byte SchoolType2 = SchoolType
    label var SchoolType2 "School type (alias)"
}

* Safety: ensure core covariates exist; warn if not.
foreach v in outcome exp parents_students SchoolType SchoolType2 Community Sex Income LeftRight EgocentricEvaluation SocioEvaluation GovtShould {
    capture confirm variable `v'
    if _rc di as error "Variable `v' is missing."
}

/*** Clean estimates memory ***/
estimates clear
eststo clear

/******************************************************************************************
 FIGURE 1. Distribution by group
*******************************************************************************************/
capture noisily graph bar if GovtShould!=5, over(parents_students, label(labsize(vsmall))) over(GovtShould, label(labsize(small))) ///
    ytitle("% of respondents") caption("Government Spending on Education should be ...", position(6)) ///
    blabel(bar, format(%9.1f))
graph export "fig1_distribution.eps", replace

/******************************************************************************************
 APPENDIX TABLE 1. Balance table
*******************************************************************************************/
* Create dummies from categorical controls
tab Community, gen(Communities)
tab Sex, gen(gend)
tab parents_students, gen(parstu)

iebaltab parstu1 parstu2 gend* Age Communities1 Communities2 Communities3 Communities4 LeftRight, grpvar(exp) save("apptab1.xlsx") replace
	
/******************************************************************************************
 TABLE 2 (Manuscript) + Appendix A4. Baseline models
*******************************************************************************************/
ologit outcome i.exp
eststo m1

ologit outcome i.exp i.parents_students i.SchoolType i.Community i.Sex Income LeftRight EgocentricEvaluation SocioEvaluation
eststo m2

esttab m1 m2 using "tab2_baseline.rtf", replace ///
    cells(b(star fmt(%9.3f)) se(par)) ///
    stats(r2_p N, fmt(%9.3f %9.0g) labels("Pseudo R-squared")) legend label collabels(none) ///
    varlabels(_cons "Constant" EgocentricEvaluation "Egocentric" SocioEvaluation "Sociotropic" LeftRight "Left-Right" Income "Income") ///
    drop(0.exp 0.parents_students 1.SchoolType 1.Sex 1.Community)

/******************************************************************************************
 FIGURE 2. Predicted likelihood by treatment
*******************************************************************************************/
ologit outcome i.exp i.parents_students i.SchoolType i.Community i.Sex Income LeftRight EgocentricEvaluation SocioEvaluation
margins exp
marginsplot, ytitle("Predicted likelihood") xtitle("") title("") plot( , label("Less than now" "Same as now" "More than now" "Much more than now")) name("fig2") legend(pos(6) rows(1))
graph export "fig2_predicted_by_treatment.eps", name("fig2") replace


/******************************************************************************************
 FIGURE 3. Sociotropic evaluations × treatment
*******************************************************************************************/
ologit outcome i.exp##c.SocioEvaluation i.SchoolType EgocentricEvaluation i.parents_students i.Community i.Sex Income LeftRight
eststo h5
margins exp, at(SocioEvaluation=(0(0.2)1)) predict(outcome(1)) predict(outcome(4))
marginsplot, xtitle ("Sociotropic Evaluations") ytitle("Predicted likelihood") plot( , label("Less than now" "Same as now" "More than now" "Much more than now")) name("fig3") legend(pos(6) rows(2)) title("")
graph export "fig3_sociotropic.eps", name("fig3") replace

/******************************************************************************************
 FIGURE 4. Egocentric evaluations × treatment
*******************************************************************************************/
ologit outcome i.exp##c.EgocentricEvaluation i.SchoolType i.parents_students i.Community i.Sex Income LeftRight SocioEvaluation
eststo h6
margins exp, at(EgocentricEvaluation=(0(0.2)1)) predict(outcome(1)) predict(outcome(4))
marginsplot, xtitle ("Egocentric Evaluations") ytitle("Predicted likelihood") plot( , label("Less than now" "Same as now" "More than now" "Much more than now")) ylab(0(0.1)0.6) name("fig4") legend(pos(6) rows(2)) title("")
graph export "fig4_egocentric.eps", name("fig4") replace

/******************************************************************************************
 FIGURE 5. Marginal effects of Sociotropic and Egocentric
*******************************************************************************************/
ologit outcome i.exp##c.SocioEvaluation##c.EgocentricEvaluation i.SchoolType i.parents_students i.Community i.Sex Income LeftRight 
eststo h5xh6
margins exp, at(EgocentricEvaluation=(0(0.2)1)) predict(outcome(1)) predict(outcome(4)) dydx(SocioEvaluation)
marginsplot, ytitle("Predicted likelihood") xtitle("Egocentric Evaluations") title("Marginal effects of" "Sociotropic Evaluations") plot( , label("Less than now" "Same as now" "More than now" "Much more than now")) name(sociotropic, replace) ylab(-0.5(0.5)1.1)  legend(pos(6) rows(2))
margins exp, at(SocioEvaluation =(0(0.2)1)) predict(outcome(1)) predict(outcome(4)) dydx(EgocentricEvaluation)
marginsplot, ytitle("Predicted likelihood") xtitle("Sociotropic Evaluations") title("Marginal effects of" "Egocentric Evaluations") plot( , label("Less than now" "Same as now" "More than now" "Much more than now")) name(egocentric, replace) ylab(-0.5(0.5)1.1) legend(pos(6) rows(2))
grc1leg sociotropic egocentric, name("fig5") 
graph export "fig5_marginals.eps", replace

/******************************************************************************************
 TABLE 3. Alternative moderators to explain preferences for higher public spending in education in the face of higher taxes:
*******************************************************************************************/

ologit outcome i.exp##i.SchoolType SocioEvaluation EgocentricEvaluation i.SchoolType i.parents_students i.Community i.Sex Income LeftRight 
eststo h7

ologit outcome i.exp##i.parents SocioEvaluation EgocentricEvaluation i.SchoolType i.parents_students i.Community i.Sex Income LeftRight 
eststo h8

esttab h5 h6 h7 h8 using "tab3_moderators.rtf", replace ///
    cells(b(star fmt(%9.3f)) se(par)) ///
    order(*.exp#c.SocioEvaluation *.exp#c.EgocentricEvaluation *.exp#*.SchoolType *.exp#*.parents_students 1.exp SocioEvaluation EgocentricEvaluation c.SocioEvaluation#c.EgocentricEvaluation) ///
    stats(r2_p N, fmt(%9.3f %9.0g) labels("Pseudo R-squared")) legend label collabels(none) ///
    varlabels(_cons "Constant" EgocentricEvaluation "Egocentric" SocioEvaluation "Sociotropic" LeftRight "Left-Right" Income "Income") ///
    drop(0.exp* *0.parents_students 0.parents_students* 1.SchoolType* 1.exp#1.SchoolType 1.Community 1.Sex)

/******************************************************************************************
 FIGURE 6. Ideology × treatment (OLS robustness)
*******************************************************************************************/
reg outcome i.exp##c.LeftRight SchoolType2 i.Community SocioEvaluation EgocentricEvaluation i.parents_students i.Community i.Sex Income  
margins exp,at(LeftRight=(0(0.1)1))
marginsplot,legend(pos(6) rows(1)) xtitle("Left-Right Ideological Position") ytitle("Predicted Public Spending Level") title("") name("fig6")
graph export "fig6_ideology.eps", replace name("fig6")


/******************************************************************************************
 FIGURE 7. School profiles × treatment
*******************************************************************************************/
ologit outcome i.exp##i.SchoolType2 LeftRight  i.Community SocioEvaluation EgocentricEvaluation i.parents_students i.Community i.Sex Income  
margins exp#SchoolType2,predict(outcome(1)) predict(outcome(4))
marginsplot,xdimension(SchoolType2) legend(pos(6) rows(2)) xtitle("School Type") ytitle("Predicted Likelihood") title("") plot( , label("Less than now" "Same as now" "More than now" "Much more than now"))
graph export "fig7_school_profiles.eps", replace


/******************************************************************************************
 APPENDIX TABLE A5. Alternative experimental moderators (OLS robustness)
*******************************************************************************************/
estimates clear
eststo clear

reg outcome i.exp##i.parents_students LeftRight i.SchoolType i.Community SocioEvaluation EgocentricEvaluation  i.Sex Income
eststo a1

reg outcome i.exp##i.SchoolType c.LeftRight  i.Community SocioEvaluation EgocentricEvaluation i.parents_students i.Community i.Sex Income
eststo a2

reg outcome i.exp##c.LeftRight i.SchoolType i.Community SocioEvaluation EgocentricEvaluation i.parents_students i.Community i.Sex Income
eststo a3

reg outcome i.exp##c.SocioEvaluation LeftRight i.SchoolType i.Community  EgocentricEvaluation i.parents_students i.Community i.Sex Income
eststo a4

reg outcome i.exp##c.EgocentricEvaluation LeftRight i.SchoolType i.Community SocioEvaluation  i.parents_students i.Community i.Sex Income
eststo a5

reg outcome i.exp##c.SocioEvaluation##c.EgocentricEvaluation LeftRight i.SchoolType i.Community  i.parents_students i.Community i.Sex Income
eststo a6

reg outcome i.exp##i.Community c.LeftRight i.SchoolType i.Community SocioEvaluation EgocentricEvaluation i.parents_students  i.Sex Income
eststo a7

esttab a1 a2 a3 a4 a5 a6 a7 using "appa5_ols_moderators.rtf", replace ///
    cells(b(star fmt(%9.3f)) se(par)) ///
    order(*.exp#*.parents_students *.exp#*.SchoolType *.exp#*EgocentricEvaluation *.exp#*SocioEvaluation *.exp#*LeftRight ) ///
    stats(r2_a N, fmt(%9.3f %9.0g) labels("Adjusted R-squared")) legend label collabels(none) ///
    varlabels(_cons "Constant" EgocentricEvaluation "Egocentric" SocioEvaluation "Sociotropic" LeftRight "Left-Right" Income "Income") ///
    drop(0.exp* 1.exp#1.SchoolType 1.exp#0.parents_students 0.parents_students* 1.SchoolType*)

/******************************************************************************************
 MULTINOMIAL LOGIT ROBUSTNESS
*******************************************************************************************/
* Recode dependent variable for mlogit baseline variants
capture drop outcome2
recode outcome (4=3), gen(outcome2)

* Appendix Table A6 – Multinomial logistic models (baselines across bases)
estimates clear
eststo clear

mlogit outcome2 i.exp, base(3)
eststo m1

mlogit outcome2 i.exp i.parents_students i.SchoolType i.Community i.Sex Income LeftRight EgocentricEvaluation SocioEvaluation, base(3)
eststo m2

mlogit outcome2 i.exp, base(1)
eststo m1a

mlogit outcome2 i.exp i.parents_students i.SchoolType i.Community i.Sex Income LeftRight EgocentricEvaluation SocioEvaluation, base(1)
eststo m2a

mlogit outcome2 i.exp, base(2)
eststo m1b

mlogit outcome2 i.exp i.parents_students i.SchoolType i.Community i.Sex Income LeftRight EgocentricEvaluation SocioEvaluation, base(2)
eststo m2b

esttab m1 m2 m1a m2a m1b m2b using "appa6_mlogit_baselines.rtf", replace ///
    cells(b(star fmt(%9.3f)) se(par)) ///
    stats(r2_p N, fmt(%9.3f %9.0g) labels("Pseudo R-squared")) legend label collabels(none) ///
    varlabels(_cons "Constant" EgocentricEvaluation "Egocentric" SocioEvaluation "Sociotropic" LeftRight "Left-Right" Income "Income") ///
    drop(0.exp 0.parents_students 1.SchoolType 1.Sex 1.Community)
	
	
* Appendix Table A7 – Moderators with multinomial logistic regression
mlogit outcome2 i.exp##i.parents_students i.SchoolType i.Community i.Sex Income LeftRight EgocentricEvaluation SocioEvaluation
eststo m3

mlogit outcome2 i.exp##i.parents_students i.SchoolType i.Community i.Sex Income LeftRight EgocentricEvaluation SocioEvaluation, base(2)
eststo m3a

mlogit outcome2 i.exp##c.LeftRight SocioEvaluation i.SchoolType EgocentricEvaluation i.parents_students i.Community i.Sex Income 
eststo h4

mlogit outcome2 i.exp##c.LeftRight SocioEvaluation i.SchoolType EgocentricEvaluation i.parents_students i.Community i.Sex Income, base(2)
eststo h4a

mlogit outcome2 i.exp##c.SocioEvaluation i.SchoolType EgocentricEvaluation i.parents_students i.Community i.Sex Income LeftRight 
eststo h5

mlogit outcome2 i.exp##c.SocioEvaluation i.SchoolType EgocentricEvaluation i.parents_students i.Community i.Sex Income LeftRight , base(2)
eststo h5a

mlogit outcome2 i.exp##c.EgocentricEvaluation i.SchoolType i.parents_students i.Community i.Sex Income LeftRight SocioEvaluation
eststo h6

mlogit outcome2 i.exp##c.EgocentricEvaluation i.SchoolType i.parents_students i.Community i.Sex Income LeftRight SocioEvaluation, base(2)
eststo h6a

mlogit outcome2 i.exp##c.SocioEvaluation##c.EgocentricEvaluation i.SchoolType i.parents_students i.Community i.Sex Income LeftRight 
eststo h5xh6

mlogit outcome2 i.exp##c.SocioEvaluation##c.EgocentricEvaluation i.SchoolType i.parents_students i.Community i.Sex Income LeftRight , base(2)
eststo h5xh6a

mlogit outcome2 i.exp##i.Community SocioEvaluation EgocentricEvaluation i.SchoolType i.parents_students i.Community i.Sex Income LeftRight 
eststo h7

mlogit outcome2 i.exp##i.Community SocioEvaluation EgocentricEvaluation i.SchoolType i.parents_students i.Community i.Sex Income LeftRight , base(2)
eststo h7a

esttab m3 m3a h4 h4a h5 h5a h6 h6a h5xh6 h5xh6a h7 h7a using "appa7_mlogit_moderators.rtf", replace ///
    cells(b(star fmt(%9.3f)) se(par)) stats(r2_p N, fmt(%9.3f %9.0g) labels("Pseudo R-squared")) legend label collabels(none) ///
    varlabels(_cons "Constant" EgocentricEvaluation "Egocentric" SocioEvaluation "Sociotropic" LeftRight "Left-Right" Income "Income") ///
    drop(0.exp 0.parents_students 1.SchoolType 1.Sex 1.Community)


/******************************************************************************************
 APPENDIX TABLE A8. Triple interaction (OLS robustness)
*******************************************************************************************/
reg outcome i.exp##c.SocioEvaluation##c.EgocentricEvaluation LeftRight i.SchoolType i.Community  i.parents_students i.Community i.Sex Income

esttab using "appa8_triple_interaction.rtf", replace cells(b(star fmt(%9.3f)) se(par)) stats(r2_a N, fmt(%9.3f %9.0g)) label


/******************************************************************************************
 Wrap up
*******************************************************************************************/
log close
di as txt "Replication completed."
